#define DEBUG
#include <cstdio>
#include <cstring>

using namespace std;

const int maxn=70000;

int min(int a, int b) {
  return a<b ? a : b;
}

int main() {
#ifdef DEBUG
  freopen("3320.in", "r", stdin);
  freopen("3320.out", "w", stdout);
#endif

  static char s[maxn+2];
  static int f[maxn+1][11], g[maxn+1][11][11];
  static bool need[maxn+1];
  int n, ans=0;
  scanf("%d", &n);
  scanf("%s", s+1);

  memset(f, 127, sizeof(f));
  memset(g, 127, sizeof(g));
  f[0][s[1]-'a']=0;
  for (int i=1; i<=n; i++) {
    if (s[i]=='e') {
      need[i+1]=true;
      ans += 2;
      for (int j=0; j<11; j++) {
	f[i][j] = f[i-1][j];
	for (int k=0; k<11; k++) {
	  g[i][j][k] = g[i-1][j][k];
	}
      }
    }
    for (int j=0; j<11; j++) {
      if (j+'a'!='e') {
	if (!need[i] && j!=s[i]-'a') {
	  f[i][j] = min(f[i][j], f[i-1][j]);
	}
	f[i][j] = min(f[i][j], f[i-1][s[i]-'a']+2);
	if (j!=s[i]-'a') {
	  f[i][j] = min(f[i][j], g[i-1][s[i]-'a'][j]);
	}
	f[i][j] = min(f[i][j], g[i-1][s[i]-'a'][s[i]-'a']+2);

	for (int k=0; k<11; k++) {
	  if (k+'a'!='e') {
	    if (j!=s[i]-'a') {
	      g[i][j][k] = min(g[i][j][k], f[i-1][j]+3);
	    }
	    g[i][j][k] = min(g[i][j][k], f[i-1][s[i]-'a']+5);
	    if (j!=s[i]-'a' && k!=s[i]-'a') {
	      g[i][j][k] = min(g[i][j][k], g[i-1][j][k]+1);
	    }
	    if (k!=s[i]-'a') {
	      g[i][j][k] = min(g[i][j][k], g[i-1][s[i]-'a'][k]+3);
	    }
	    if (j!=s[i]-'a') {
	      g[i][j][k] = min(g[i][j][k], g[i-1][j][s[i]-'a']+3);
	    }
	    g[i][j][k] = min(g[i][j][k], g[i-1][s[i]-'a'][s[i]-'a']+5);
	  }
	}
      }
    }
  }

  printf("%d", ans+f[n][10]-2);

  fclose(stdin);
  fclose(stdout);
  return 0;
}
